{template '_header'}

<div class="page-heading"> 
	<span class='pull-right'>
		{ifp 'seckill.task.add'}
			<a class="btn btn-primary btn-sm" href="{php echo webUrl('seckill/task/add')}">添加新专题</a>
		{/if}
        {if !empty($item['id'])}
            {ifp 'seckill.room'}
            <a class="btn btn-success btn-sm" href="{php echo webUrl('seckill/room',array('taskid'=>$item['id']))}">会场管理</a>
            {/if}
        {/if}
		<a class="btn btn-default  btn-sm" href="{php echo webUrl('seckill/task')}">返回列表</a>
	</span>
    <h2>{if !empty($item['id'])}编辑{else}添加{/if}专题
        <small>{if !empty($item['id'])}修改【{$item['title']}】{/if}</small>
    </h2>
</div>

<form {ife 'seckill.task' $item}action="" method="post"{/if} class="form-horizontal form-validate " enctype="multipart/form-data">
<input type="hidden" name="id" value="{$item['id']}"/>

<div class="panel panel-default">
    <div class="panel-heading">
        专题信息
    </div>
    <div class="panel-body">
        <div class="form-group">
            <label class="col-sm-2 control-label must">专题名称</label>
            <div class="col-sm-9 col-xs-12 ">
                {ife 'seckill.task' $item}
                <input type="text" name="title" class="form-control" value="{$item['title']}"
                       data-rule-required="true" />
                {else}
                <div class='form-control-static'>{$item['title']}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">标签</label>
            <div class="col-sm-9 col-xs-12 ">
                {ife 'seckill.task' $item}
                <input type="text" name="tag" class="form-control" value="{$item['tag']}"/>
                <span class="help-block">显示在首页橱窗头部，和商品详情页面</span>
                {else}
                <div class='form-control-static'>{$item['tag']}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">分类</label>
            <div class="col-sm-9 col-xs-12 ">
                {ife 'seckill.task' $item}
                <select class="form-control" name="cateid">
                    <option value=""></option>
                    {loop $category $k $v}
                    <option value="{$k}" {if $item['cateid']==$k}selected{/if}>{$v['name']}</option>
                    {/loop}
                </select>
                {else}
                <div class='form-control-static'>{$category[$item['cateid']]['name']}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">秒杀点</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'seckill.task' $item}
                <?php for($i=0;$i<=23;$i++) { ?>
                <label class="checkbox-inline" style="width:50px">
                    <input type="checkbox" name="times[]" value="{$i}" {if in_array($i, $alltimes)}checked{/if} />{$i}点
                </label>
                <?php } ?>
                {else}
                <div class='form-control-static'>
                    <?php for($i=0;$i<=23;$i++) {?>
                    {if in_array($i, $alltimes)}{$i}点;{/if}
                    <?php } ?>
                </div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">自动取消</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'seckill.task' $item}
                <input type="text" name="closesec" class="form-control" value="{php echo $item['closesec']<=0?'900':$item['closesec']}"/>
                <span class="help-block">抢购成功，不付款多少秒之后，自动取消资格，默认900秒(15分钟)</span>
                {else}
                <div class='form-control-static'>{php echo $item['closesec']<=0?'120':$item['closesec']}s</div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">状态</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'seckill.task' $item}
                <label class='radio-inline'>
                    <input type='radio' name='enabled' value=1' {if $item['enabled']==1}checked{/if} /> 启用
                </label>
                <label class='radio-inline'>
                    <input type='radio' name='enabled' value=0' {if $item['enabled']==0}checked{/if} /> 禁用
                </label>
                <span class="help-block">设置禁用，不出现在搜索列表</span>
                {else}
                <div class='form-control-static'>{if empty($item['enabled'])}禁用{else}启用{/if}</div>
                {/if}
            </div>
        </div>

    </div>
</div>





<div class="panel panel-default">
    <div class="panel-heading">
        分享及标题设置
    </div>
    <div class="panel-body">
        <div class="form-group">
            <label class="col-sm-2 control-label">页面标题</label>
            <div class="col-sm-9 col-xs-12 ">
                {ife 'seckill.task' $item}
                <input type="text" name="page_title" class="form-control" value="{$item['page_title']}"
                       data-rule-required="true"/>
                <span class="help-block">专题专题的页面标题 ,默认为 专题标题</span>
                {else}
                <div class='form-control-static'>{$item['page_title']}</div>
                {/if}
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-2 control-label">分享标题</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'seckill.task' $item}
                <input type="text" name="share_title" id="share_title" class="form-control" value="{$item['share_title']}" />
                <span class='help-block'>如果不填写，默认为页面标题</span>
                {else}
                <div class='form-control-static'>{$item['share_title']}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">分享图标</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'seckill.task' $item}
                {php echo tpl_form_field_image('share_icon', $item['share_icon'])}
                {else}
                {if !empty($item['share_icon'])}
                <a href='{php echo tomedia($item['share_icon'])}' target='_blank'>
                <img src="{php echo tomedia($item['share_icon'])}" style='width:100px;border:1px solid #ccc;padding:1px' />
                </a>
                {/if}
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">分享描述</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'seckill.task' $item}
                <textarea name="share_desc" class="form-control" >{$item['share_desc']}</textarea>
                {else}
                <div class='form-control-static'>{$item['share_desc']}</div>
                {/if}
            </div>
        </div>


    </div>
</div>

<div class="form-group">
    <label class="col-sm-1 control-label"></label>
    <div class="col-sm-9 col-xs-12">
        {ife 'seckill.task' $item}
        <input type="submit" value="提交" class="btn btn-primary"/>
        {/if}
        <input type="button" name="back" onclick='history.back()' {ifp 'seckill.task'}style='margin-left:10px;'{/if}value="返回列表" class="btn btn-default" />
    </div>
</div>

</form>


<script language='javascript'>
    function formcheck() {
        if ($("#advname").isEmpty()) {
            Tip.focus("advname", "请填写专题名称!");
            return false;
        }
        return true;
    }
    $(function(){
        require(['jquery.ui'],function(){
            //$(".ui-sortable").sortable();
        })
        $('#btn-add-time').click(function(){

            var time = $('#select-times').val();
            $('#time-' + time).show();
            $(':hidden[name="timeopen['+time+']"]').val(1);
            $('#times').show();

        });
        $('.btn-delete-time').click(function(){
            var time = $(this).data('time');
            $('#time-' + time).hide();
            $(':hidden[name="timeopen['+time+']"]').val(0);
            var has = false;
            for(var i=0;i<=23;i++){
                if( $(':hidden[name="timeopen['+i+']"]').val()=='1'){
                    has =true;
                    break;
                }
            }
            if(!has){
                $('#times').hide();
            }


        })

    })
</script>

{template '_footer'}